package DataStructureAndAlgorithm.CSP.Day02;


//模拟题----命令行选项
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class AcWing_3199 {

    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);

        String instru=scan.next();
        int len=instru.length();
        int n=scan.nextInt();
        scan.nextLine();
        for(int i=1;i<=n;i++)
        {
            String str=scan.nextLine();
            String[] split = str.split(" ");
            //判断每一个指令
            Set<Character> set=new HashSet<>();
            Map<Character,String> map=new HashMap<>();
            for(int j=1;j<split.length;j++)
            {
                String temp=split[j];
                //分析停止
                if(temp.length()>2)
                    break;
                char ch=temp.charAt(1);
                int k=instru.indexOf(ch);
                //-x 开头
                if(k==-1||temp.charAt(0)!='-')
                    break;
                if(k+1<len&&instru.charAt(k+1)==':')
                {
                    //带参数
                    if(j+1<split.length)
                        set.add(ch);
                    if(j+1<split.length)
                        map.put(ch,split[j+1]);
                    j++;
                }
                else
                {
                    //不带参数
                    set.add(ch);
                }
            }
            //去重，排序
            List<Character> list=new ArrayList<>(set);
            Collections.sort(list);
            System.out.print("Case "+i+":");
            for(int m=0;m<list.size();m++)
            {
                System.out.print(" -");
                System.out.print(list.get(m));
                if(map.get(list.get(m))!=null)
                    System.out.print(" "+map.get(list.get(m)));
            }
            System.out.println();
        }


        scan.close();

    }
}
